package com.salesmanager.core.modules.sms;

import com.salesmanager.core.constants.CacheConstants;
import com.salesmanager.core.modules.cache.Xm9mRedisTemplateSupport;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created by Liutong on 5/14/16.
 */
public abstract class AbstractSmsService implements SmsService {
    @Autowired
    private Xm9mRedisTemplateSupport redisTemplate;

    public void save(String telPhone ,Object value,int timeoutMiniute) {
//        if (!redisTemplate.EXISTS(CacheConstants.SMS_CODES)){
        redisTemplate.HSET(CacheConstants.SMS_CODES,telPhone,value,timeoutMiniute);
//        }

    }

    public Object getByTelephone(String telPhone){
        Object object = null;
//        object = redisTemplate.HGET(CacheConstants.SMS_CODES,telPhone);
        return  object;
    }

    public void delete(String telPhone) {
        if (redisTemplate.EXISTS(CacheConstants.SMS_CODES)) {
            redisTemplate.HDEL(CacheConstants.SMS_CODES,telPhone);
        }
    }
}
